require('es6-promise').polyfill();

import axios from 'axios'


function loadCalendarData(data) {
  return {
    type: 'LOAD_CALENDAR_DATA',
    data
  }
}


export function loadCalendarDataAsync(data) {
  return function(dispatch) {
    return axios.post('/api/calendar/query', data).then(
      resp => dispatch(loadCalendarData(resp.data)),
      error => alert(error.data.errMsg)
    )
  }
}

export function createCalendarDataAsync(data) {
  return function(dispatch) {
    return axios.post('/api/calendar/create', data).then(
      resp => dispatch(loadCalendarDataAsync(data)),
      error => alert(error.data.errMsg)
    )
  }
}

export function deleteCalendarDataAsync(data) {
  return function(dispatch) {
    return axios.post('/api/calendar/delete', data).then(
      resp => dispatch(loadCalendarDataAsync(data)),
      error => alert(error.data.errMsg)
    )
  }
}
